<template>
	<a-switch 
		v-model:checked = 'checked' 
		:disabled 		= 'disabled'
		:loading 		= 'loading'
		@change 		= 'onChange'
	/>
</template>

<script>
	import { ref } from 'vue'
	import { Switch } from 'ant-design-vue'
	app.use(Switch)
	export default{
		props:{
			size		: { type:String, default:'small' },
			value 		: [ Boolean, Number, String ],
			loading		: Boolean,
			disabled	: Boolean,
			name 		: String,
			label 		: String,
			form 		: Object,
			isNumber 	: { type:Boolean, default:true }
		},
		emits:{
			change:null,
			'update:value':null
		},
		setup({value, isNumber}, ctx){
			const checked = ref( isNumber ? (+value ? true : false) : value )
			return {
				checked,
				onChange: value => {
					if(isNumber){ value = +value ? 1 : 0 }
					ctx.emit('update:value', value)
					ctx.emit('change', value)
				}
			}
		}
	}
</script>